package SwingView.Lecture;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.nio.file.Files;

import JDBC.InstructorLectureActivities;
import SwingController.CmsPresenter;
import SwingModel.CmsInstructor;
import SwingModel.CmsLecture;
import SwingModel.CmsUser;
import SwingView.CmsMainView;

import java.util.List;

public class ALLectureDelete implements ActionListener{

	private final CmsLecture lect;
	
	public ALLectureDelete(CmsLecture lect){
		this.lect = lect;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		CmsInstructor instructor =  (CmsInstructor)CmsPresenter.user;
		
		//instructor deleteLecture
		InstructorLectureActivities.deleteLecture(lect.getLectureID());
		
		try {
			//delete file from lecture folder
			Files.delete(lect.getLectureFile().toPath());
		} catch (IOException e1) {
			System.err.println("ERROR: fail to delete file from lecture folder");
		}
		
		//display lecture instructor Page
		List<CmsLecture> listOfLecture = InstructorLectureActivities.getListOfLecture(instructor.getUsername(), instructor.getSelectedCourse().getCourseID());
		CmsPresenter.mainView.displayLectureInstructorPage(listOfLecture);
	}

}
